import { ajax } from '../lib/ajax.js';
import { tools } from '../lib/tools.js';

let txt_title = document.getElementById('txt_title');
let txt_source = document.getElementById('txt_source');
let txt_info = document.getElementById('txt_info');
let btnOk = document.getElementById('btnOk');

btnOk.addEventListener('click', () => {
  let news = {
    title: txt_title.value,
    source: txt_source.value,
    info: txt_info.value,
  };

  ajax.post('/crud/news', news, (data) => {
    alert(data.message);
    if (data.success) {
      txt_title.value = '';
      txt_source.value = '';
      txt_info.value = '';
    }
  });
});
